<template>
    <div class="page" data-page="approveApply" style="z-index: 2;">
        <div class="link-page-nav">
            <a href="#" class="link" @click="goBack()">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-top">
            <div class="link-page-title">审批说明</div>
        </div>
        <div class="page-content" id="work_kalarm_{{getNewId}}" style="padding-top: 0;padding-bottom: 100px;">
            <div style="margin-top:0px;margin-bottom:8px;">
                <div style="margin: 0 20px;position: relative;">
                	<textarea class="textareaDesc cancle-ios-write" placeholder="简洁明了的描述有利于说明现场情况。尝试用语音输入更便捷" id="desc_{{getNewId}}" name="bjms"></textarea>
                	<i class="iconfont icon-yuyin speechInputDetails" id="approvalInputDetails_{{getNewId}}"></i>
                </div>
            </div>
		    <div class="submitBtn" @click="passWorkApply(1)">同意</div>
            <div style="text-align: center;">
                <a hred="#" class="returnBtn" @click="passWorkApply(2)">拒绝</a>
            </div>  
        </div>
    </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            var $ = self.$;
            self.taskId = self.$route.params.taskId;
        },
        data: function () {
            return {
                imageArr: [],
                getNewId: (new Date()).getTime()
            }
        },
        methods: {
        	goBack:function(){
        		var self = this;
        		 var formData = app.form.convertToData('#work_kalarm_'+self.getNewId);
                 var bjms = jQuery.trim(formData.bjms);
                 if (bjms == "") {
                	 app.router.back();
                 }else{
	        		  //是否保存
	        		  isSaveData( function(){
	        		     	//点不保存之后的操作    
	        			  	app.router.back();
	        		   },function(){
	        		     	// 点返回继续之后的操作
	        		   });
                }
        	},
        	passWorkApply: function (btnType) {//提交数据
                var self = this;
                var formData = app.form.convertToData('#work_kalarm_'+self.getNewId);
                var bjms = jQuery.trim(formData.bjms);
                if (bjms == "") {
                    app.methods.showToastCenter("请填写描述");
                    return;
                }
                common.loading(1);
                var param = {
                    id:self.taskId,
                    approvalDesc: bjms,
                    approvalAccount:userInfor.accountName
                };
                if(btnType==1){//通过
	                Dao.passWorkApply(param, function (data) {
		                	common.loading(0);
		                    app.methods.showToastBottom("操作成功");
		                    app.router.back();
		                    app.view.current.el.f7View.router.currentPageEl.f7Component.backRefreshWorkApply(); 
	                }, true);
                }else{//拒绝
                	Dao.nopassWorkApply(param, function (data) {
	                	common.loading(0);
	                    app.methods.showToastBottom("操作成功");
	                    app.router.back();
	                    app.view.current.el.f7View.router.currentPageEl.f7Component.backRefreshWorkApply(); 
                	}, true);
                }
            },
            initTbPiker: function () {
                var self = this;
                $("#approvalInputDetails_"+self.getNewId).click(function (e) {
                    //第二个参数是否需要保存语音
                    native.startVoice("desc_"+self.getNewId, false);
                });
            },
            //语音输入回调
            voiceCollectionData: function (voiceStr, componentId) {
                var text = $("#" + componentId).val();
                if (!voiceStr || "" === voiceStr.trim()) {
                    app.methods.showToastCenter("未能识别您说的语音,请重试。");
                } else {
                    $("#" + componentId).val(text + voiceStr);
                }
            },
            submit:function(){
            	 //是否保存
       		   isSaveData(function(){
       		      	//点不保存之后的操作    
       		      	console.error(2);
       			  app.router.back();
       		   },function(){
       		     	// 点返回继续之后的操作
       		     	console.error(1);
       		   });
            }
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                self.initTbPiker();
            }
        }
    }
</script>

<style>
    .textareaDesc {
        font-size: 15px;
        width: 100%;
        padding: 18px;
        border: 1px solid rgba(225,225,225,.9);
	    box-shadow: 0 1px 10px 0 rgba(181,200,206,.5);
	    border-radius: 6px;
	    margin-bottom: 20px;
	    min-height: 250px;
    }
    
    .speechInputDetails {
        position: absolute;
	    bottom: 0;
	    right: 0;
	    color: #333333;
	    padding: 10px;
    }
    .submitBtn{
        margin: 58px 20px 33px 20px;
        height: 44px;
        line-height: 44px;
        background: rgba(36, 113, 202, 1);
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
        border: 0;
        width: 90%;
        text-align: center;
        font-size: 16px;
        letter-spacing: 2px;
    }
</style>